import "./image.mp-sfc.css";
import { defineComponent, computed } from "vue";
import { createNamespace, transformSize } from "../utils";
import { propsObject } from "./props";
import FanAspectRatio from "../aspect-ratio/aspect-ratio.js";
const __vue_sfc__ = defineComponent({
  name: createNamespace("Image")[0],
  options: {
    // https://uniapp.dcloud.io/matter.html#mp
    virtualHost: true
  },
  components: { FanAspectRatio },
  emits: ["click", "longpress", "load"],
  props: propsObject,
  setup(props, context) {
    const radiusStyle = computed(() => {
      return props.radius ? `border-radius:${transformSize(props.radius)};` : "";
    });
    const theStyle = computed(() => {
      return `overflow:hidden;position:relative;${radiusStyle.value}`;
    });
    const aspectRatioNum = computed(() => props.mode === "widthFix" ? 0 : props.aspectRatio);
    const imgStyle = computed(() => {
      const { height } = props;
      const h = aspectRatioNum.value || height ? "100%" : transformSize(height);
      return `height:${h};${radiusStyle.value}`;
    });
    const imgMode = computed(() => {
      const { height, mode } = props;
      if (mode)
        return mode;
      return !height ? "widthFix" : "scaleToFill";
    });
    const onClick = (e) => context.emit("click", e);
    const onLongpress = () => context.emit("longpress");
    const onLoad = (e) => context.emit("load", e);
    return { radiusStyle, theStyle, imgStyle, imgMode, aspectRatioNum, onClick, onLongpress, onLoad };
  }
});
import { normalizeClass as _normalizeClass, normalizeStyle as _normalizeStyle, openBlock as _openBlock, createElementBlock as _createElementBlock, renderSlot as _renderSlot, resolveComponent as _resolveComponent, withCtx as _withCtx, createBlock as _createBlock } from "vue";
const _hoisted_1 = ["src", "mode", "show-menu-by-longpress", "lazy-load"];
function __vue_render__(_ctx, _cache) {
  const _component_FanAspectRatio = _resolveComponent("FanAspectRatio");
  return _openBlock(), _createBlock(_component_FanAspectRatio, {
    style: _normalizeStyle(_ctx.theStyle),
    "aspect-ratio": _ctx.aspectRatioNum,
    width: _ctx.width,
    height: _ctx.height,
    onClick: _ctx.onClick
  }, {
    default: _withCtx(() => [
      !_ctx.src ? (_openBlock(), _createElementBlock(
        "div",
        {
          key: 0,
          style: _normalizeStyle("height:100%;" + _ctx.radiusStyle),
          class: _normalizeClass(["fan-img--empty", { light: _ctx.placeholderLight }])
        },
        null,
        6
        /* CLASS, STYLE */
      )) : (_openBlock(), _createElementBlock("image", {
        key: 1,
        style: _normalizeStyle(_ctx.imgStyle),
        class: "fan-img",
        src: _ctx.src,
        mode: _ctx.imgMode,
        "show-menu-by-longpress": _ctx.showMenuByLongpress,
        "lazy-load": _ctx.lazyLoad,
        onLongpress: _cache[0] || (_cache[0] = (...args) => _ctx.onLongpress && _ctx.onLongpress(...args)),
        onLoad: _cache[1] || (_cache[1] = (...args) => _ctx.onLoad && _ctx.onLoad(...args))
      }, null, 44, _hoisted_1)),
      _renderSlot(_ctx.$slots, "default")
    ]),
    _: 3
    /* FORWARDED */
  }, 8, ["style", "aspect-ratio", "width", "height", "onClick"]);
}
__vue_sfc__.render = __vue_render__;
var stdin_default = __vue_sfc__;
export {
  stdin_default as default
};
